<?
include "include/database.php";
include "classes/cls_klant.php";

$klant = new cls_klant;

if($_GET['editclick'])
{
	$klantid = $_GET["id"];

	if($klantid)
	{
		//verzamel alle gegevens:
		$voornaam 		= $_POST['voornaam'];
		$achternaam		= $_POST['achternaam'];
		$geboortedatum  = $_POST['geboortedatum'];
		$straat 		= $_POST['straat'];
		$postcode 		= $_POST['postcode'];
		$plaats 		= $_POST['plaats'];
		$telefoon 		= $_POST['telefoon'];
		$nieuwsbrief 	= $_POST['nieuwsbrief'];
		$email		 	= $_POST['email'];
		$username 		= $_POST['username'];
		$password		= $_POST['password'];
		

		$klant->edit($voornaam,$achternaam,$straat,$postcode,$plaats,$telefoon,$nieuwsbrief,$email,$klantid,$geboortedatum,$username,$password);
		
		print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"1; URL=admin_klanten.php?list=1\">";
		print "Wijziging succesvol.<br>";
		print "<blink>U wordt doorgestuurd...</blink>";
	}
}

$query = mysql_query("SELECT * FROM sessie WHERE ip = '".$_SERVER['REMOTE_ADDR']."'");
$result = mysql_fetch_array($query);
$klantid = $result['idklant'];

$query = mysql_query("SELECT * FROM klant WHERE id = '" . $klantid ."'");
$result = mysql_fetch_array($query);


if($_GET['edit'])
{
	//pas titel aan:
	echo "<title>Admin, bewerk een klant.</title>";
	//krijg id klant:
	$klantid = $_GET["id"];
	
	//wanneer er een id is ingevuld vul formulier in:
	if($klantid)
	{
		//$query = mysql_query("SELECT * FROM klant WHERE id = '" . $klantid ."'");
		
		
		$query = mysql_query("SELECT * FROM klant WHERE id = '" . $klantid ."'");
		$result = mysql_fetch_object($query);
			
		//html form hier met print !
		?>
        
 		<form method="post" action="admin_klanten.php?editclick=1&id=<? print $result->id; ?>" name="klant_wijzig">
		
        <br />
<br />
<br />
<br />
<br />
<table width="31%" border="0" align="center">
<tr>
				<td width="52%"><b>Nr:</b></td>
	  <td width="48%"><input name="klantnr" type="text" value="<? print $klantid; ?>" size="5" disabled></td>
		  </tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>E-Mail:</b></td>
				<td><input name="email" type="text" value="<? print $result->email; ?>"></td>
			</tr>
			<tr>
				<td><b>Gebruikersnaam:</b></td>
				<td><input name="username" type="text" value="<? print $result->username; ?>"></td>
			</tr>
			<tr>
				<td><b>Wachtwoord:</b></td>
				<td><input name="password" type="text" value="<? print $result->password; ?>"></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Voornaam:</b></td>
				<td><input name="voornaam" type="text" id="voornaam" value="<? print $result->naam; ?>"></td>
			</tr>
			<tr>
				<td><b>Achternaam:</b></td>
				<td><input name="achternaam" type="text" value="<? print $result->achternaam; ?>"></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Adres:</b></td>
				<td><input name="straat" type="text" value="<? print $result->adres; ?>"></td>
			</tr>
			<tr>
				<td><b>Postcode:</b></td>
				<td><input name="postcode" type="text" value="<? print $result->postcode; ?>" size="5"></td>
			</tr>
			<tr>
				<td><b>Woonplaats:</b></td>
				<td><input name="plaats" type="text" value="<? print $result->plaats; ?>"></td>
			</tr>
			<tr>
				<td><b>Telefoon:</b></td>
				<td><input name="telefoon" type="text" value="<? print $result->telefoonnummer; ?>"></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Nieuws:</b></td>
				<td>
				<select name="nieuwsbrief">
					<option <? if($result->nieuwsbrief == "Ja"){ print "selected"; } ?>>Ja</option>
					<option <? if($result->nieuwsbrief == "Nee"){ print "selected"; } ?>>Nee</option>
				</select>				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><b>Openstaande Facturen:</b></td>
				<td><a href="admin_facturen.php?sub=getinvoice&klantnr=<? print $result->klantnr; ?>">Klik hier</a></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><input type="submit" value="Wijzig" name="wijzig"></td>
				<td>&nbsp;</td>
			</tr>
		</table>
		</form>
        <?
			break;
		//Wanneer er een klant geedit word en id is gecheckt dan
		//form en gegevens;
	}
	else
	{
		echo "no klantid";
	}
}
?>
<br /><BR />
<table width="19%" border="0" align="center">
<tr>
				<td width="25%"><b>Naam:</b></td>
				<td width="75%"><? print $result['naam']; ?></td>
			</tr>
			<tr>
				<td><b>achternaam:</b></td>
				<td><? print $result['achternaam']; ?></td>
			</tr>
			<tr>
				<td><b>Adres:</b></td>
				<td><? print $result['adres']; ?></td>
			</tr>
            <tr>
				<td><b>Postcode:</b></td>
				<td><? print $result['postcode']; ?></td>
			</tr>
                        <tr>
				<td><b>Plaats:</b></td>
				<td><? print $result['plaats']; ?></td>
			</tr>
            <tr>
				<td><b>Telefoonnummer:</b></td>
				<td><? print $result['telefoonnummer']; ?></td>
			</tr>
                        <tr>
				<td><b>Geboortedatum:</b></td>
				<td><? print $result['geboortedatum']; ?></td>
			</tr>
                        <tr>
				<td><b>Email:</b></td>
				<td><? print $result['email']; ?></td>
			</tr>
                        <tr>
				<td><b>Nieuwsbrief:</b></td>
				<td><? print $result['nieuwsbrief']; ?></td>
			</tr>
                        <tr>
				<td><b>Username:</b></td>
				<td><? print $result['username']; ?></td>
			</tr>
                        <tr>
				<td><b>Password:</b></td>
				<td><? print $result['password']; ?></td>
            </tr>
                <tr>
				<td><b><a href="index.php?page=account&edit=1&id=<? print $result['id']; ?>"> Edit account </a></b></td>
				<td><b><a href="index.php?page=account&delete=1&id=<? print $result['id']; ?>"> Delete account </a></b></td>
			</tr>
		</table>
        
